home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / phozon.c < prev    next >
C/C++ Source or Header  |  1999-08-02  |  8KB  |  262 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. extern unsigned char *phozon_spriteram;
  13.  
  14. /***************************************************************************
  15.  
  16.   Convert the color PROMs into a more useable format.
  17.  
  18.   The palette PROMs are connected to the RGB output this way:
  19.  
  20.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  21.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  22.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  23.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  24.  
  25. ***************************************************************************/
  26. void phozon_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom){
  27.     int i;
  28.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  29.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  30.  
  31.     for (i = 0; i < Machine->drv->total_colors; i++){
  32.         int bit0,bit1,bit2,bit3;
  33.  
  34.         /* red component */
  35.         bit0 = (color_prom[0] >> 0) & 0x01;
  36.         bit1 = (color_prom[0] >> 1) & 0x01;
  37.         bit2 = (color_prom[0] >> 2) & 0x01;
  38.         bit3 = (color_prom[0] >> 3) & 0x01;
  39.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  40.         /* green component */
  41.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  42.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  43.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  44.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  45.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  46.         /* blue component */
  47.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  48.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  49.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  50.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  51.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  52.  
  53.         color_prom++;
  54.     }
  55.  
  56.     color_prom += 2*Machine->drv->total_colors;
  57.     /* color_prom now points to the beginning of the lookup table */
  58.  
  59.     /* characters */
  60.     for (i = 0; i < TOTAL_COLORS(0); i++)
  61.         COLOR(0,i) = (*(color_prom++) & 0x0f);
  62.     /* sprites */
  63.     for (i = 0; i < TOTAL_COLORS(2); i++)
  64.         COLOR(2,i) = (*(color_prom++) & 0x0f) + 0x10;
  65. }
  66.  
  67. int phozon_vh_start( void ) {
  68.     /* set up spriteram area */
  69.     spriteram_size = 0x80;
  70.     spriteram = &phozon_spriteram[0x780];
  71.     spriteram_2 = &phozon_spriteram[0x780+0x800];
  72.     spriteram_3 = &phozon_spriteram[0x780+0x800+0x800];
  73.  
  74.     return generic_vh_start();
  75. }
  76.  
  77. void phozon_vh_stop( void ) {
  78.  
  79.     generic_vh_stop();
  80. }
  81.  
  82. void phozon_draw_sprite(struct osd_bitmap *dest,unsigned int code,unsigned int color,
  83.     int flipx,int flipy,int sx,int sy)
  84. {
  85.     drawgfx(dest,Machine->gfx[2],code,color,flipx,flipy,sx,sy,&Machine->drv->visible_area,
  86.         TRANSPARENCY_PEN,0);
  87. }
  88.  
  89. void phozon_draw_sprite8(struct osd_bitmap *dest,unsigned int code,unsigned int color,
  90.     int flipx,int flipy,int sx,int sy)
  91. {
  92.     drawgfx(dest,Machine->gfx[3],code,color,flipx,flipy,sx,sy,&Machine->drv->visible_area,
  93.         TRANSPARENCY_PEN,0);
  94. }
  95.  
  96. /***************************************************************************
  97.  
  98.   Draw the game screen in the given osd_bitmap.
  99.   Do NOT call osd_update_display() from this function, it will be called by
  100.   the main emulation engine.
  101.  
  102. ***************************************************************************/
  103. void phozon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  104. {
  105.     int offs;
  106.  
  107.  
  108.     /* for every character in the video RAM, check if it has been modified */
  109.     /* since last time and update it accordingly. */
  110.     for (offs = videoram_size - 1;offs >= 0;offs--)
  111.     {
  112.         if (dirtybuffer[offs])
  113.         {
  114.             int sx,sy,mx,my;
  115.  
  116.  
  117.             dirtybuffer[offs] = 0;
  118.  
  119.             /* Even if Phozon screen is 28x36, the memory layout is 32x32. We therefore
  120.             have to convert the memory coordinates into screen coordinates.
  121.             Note that 32*32 = 1024, while 28*36 = 1008: therefore 16 bytes of Video RAM
  122.             don't map to a screen position. We don't check that here, however: range
  123.             checking is performed by drawgfx(). */
  124.  
  125.             mx = offs % 32;
  126.             my = offs / 32;
  127.  
  128.             if (my <= 1)
  129.             {       /* bottom screen characters */
  130.                 sx = my + 34;
  131.                 sy = mx - 2;
  132.             }
  133.             else if (my >= 30)
  134.             {    /* top screen characters */
  135.                 sx = my - 30;
  136.                 sy = mx - 2;
  137.             }
  138.             else
  139.             {               /* middle screen characters */
  140.                 sx = mx + 2;
  141.                 sy = my - 2;
  142.             }
  143.  
  144.             drawgfx(tmpbitmap,Machine->gfx[(colorram[offs] & 0x80) ? 1 : 0],
  145.                     videoram[offs],
  146.                     colorram[offs] & 0x3f,
  147.                     0,0,
  148.                     8*sx,8*sy,
  149.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  150.             }
  151.     }
  152.  
  153.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  154.  
  155.     /* Draw the sprites. */
  156.     for (offs = 0;offs < spriteram_size;offs += 2){
  157.         /* is it on? */
  158.         if ((spriteram_3[offs+1] & 2) == 0){
  159.             int sprite = spriteram[offs];
  160.             int color = spriteram[offs+1];
  161.             int x = (spriteram_2[offs+1]-69) + 0x100*(spriteram_3[offs+1] & 1);
  162.             int y = ( Machine->drv->screen_height ) - spriteram_2[offs] - 8;
  163.             int flipx = spriteram_3[offs] & 1;
  164.             int flipy = spriteram_3[offs] & 2;
  165.  
  166.             switch (spriteram_3[offs] & 0x3c)
  167.             {
  168.                 case 0x00:        /* 16x16 */
  169.                     phozon_draw_sprite(bitmap,sprite,color,flipx,flipy,x,y);
  170.                     break;
  171.  
  172.                 case 0x14:        /* 8x8 */
  173.                     sprite = (sprite << 2) | ((spriteram_3[offs] & 0xc0) >> 6);
  174.                     phozon_draw_sprite8(bitmap,sprite,color,flipx,flipy,x,y+8);
  175.                     break;
  176.  
  177.                 case 0x04:        /* 8x16 */
  178.                     sprite = (sprite << 2) | ((spriteram_3[offs] & 0xc0) >> 6);
  179.                     if (!flipy){
  180.                         phozon_draw_sprite8(bitmap,2+sprite,color,flipx,flipy,x,y+8);
  181.                         phozon_draw_sprite8(bitmap,sprite,color,flipx,flipy,x,y);
  182.                     }
  183.                     else{
  184.                         phozon_draw_sprite8(bitmap,2+sprite,color,flipx,flipy,x,y);
  185.                         phozon_draw_sprite8(bitmap,sprite,color,flipx,flipy,x,y+8);
  186.                     }
  187.                     break;
  188.  
  189.                 case 0x24:        /* 8x32 */
  190.                     sprite = (sprite << 2) | ((spriteram_3[offs] & 0xc0) >> 6);
  191.                     if (!flipy){
  192.                         phozon_draw_sprite8(bitmap,10+sprite,color,flipx,flipy,x,y+8);
  193.                         phozon_draw_sprite8(bitmap,8+sprite,color,flipx,flipy,x,y);
  194.                         phozon_draw_sprite8(bitmap,2+sprite,color,flipx,flipy,x,y-8);
  195.                         phozon_draw_sprite8(bitmap,sprite,color,flipx,flipy,x,y-16);
  196.                     }
  197.                     else{
  198.                         phozon_draw_sprite8(bitmap,10+sprite,color,flipx,flipy,x,y-16);
  199.                         phozon_draw_sprite8(bitmap,8+sprite,color,flipx,flipy,x,y-8);
  200.                         phozon_draw_sprite8(bitmap,2+sprite,color,flipx,flipy,x,y);
  201.                         phozon_draw_sprite8(bitmap,sprite,color,flipx,flipy,x,y+8);
  202.                     }
  203.                     break;
  204.  
  205.                 default:
  206. #ifdef MAME_DEBUG
  207. {
  208. char buf[40];
  209. sprintf(buf,"%02x",spriteram_3[offs] & 0x3c);
  210. usrintf_showmessage(buf);
  211. }
  212. #endif
  213.                     phozon_draw_sprite(bitmap,rand(),color,flipx,flipy,x,y);
  214.                     break;
  215.             }
  216.         }
  217.     }
  218.  
  219.  
  220.     /* redraw high priority chars */
  221.     for (offs = videoram_size - 1;offs >= 0;offs--)
  222.     {
  223.         if (colorram[offs] & 0x40)
  224.         {
  225.             int sx,sy,mx,my;
  226.  
  227.  
  228.             /* Even if Phozon screen is 28x36, the memory layout is 32x32. We therefore
  229.             have to convert the memory coordinates into screen coordinates.
  230.             Note that 32*32 = 1024, while 28*36 = 1008: therefore 16 bytes of Video RAM
  231.             don't map to a screen position. We don't check that here, however: range
  232.             checking is performed by drawgfx(). */
  233.  
  234.             mx = offs % 32;
  235.             my = offs / 32;
  236.  
  237.             if (my <= 1)
  238.             {       /* bottom screen characters */
  239.                 sx = my + 34;
  240.                 sy = mx - 2;
  241.             }
  242.             else if (my >= 30)
  243.             {    /* top screen characters */
  244.                 sx = my - 30;
  245.                 sy = mx - 2;
  246.             }
  247.             else
  248.             {               /* middle screen characters */
  249.                 sx = mx + 2;
  250.                 sy = my - 2;
  251.             }
  252.  
  253.             drawgfx(bitmap,Machine->gfx[(colorram[offs] & 0x80) ? 1 : 0],
  254.                     videoram[offs],
  255.                     colorram[offs] & 0x3f,
  256.                     0,0,
  257.                     8*sx,8*sy,
  258.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  259.             }
  260.     }
  261. }
  262.